Skip to content

Check image labels#32

Merged
petrpinkas merged 8 commits intomainfrom
ppinkas/SECURESIGN-2606-images-lagels
Aug 28, 2025
Merged

Check image labels#32
petrpinkas merged 8 commits intomainfrom
ppinkas/SECURESIGN-2606-images-lagels

Conversation

@petrpinkas
Copy link
Member

@petrpinkas petrpinkas commented Jul 30, 2025

Check labels of all images

  • check, if all we care of are filled,
  • if they have all the same expected values,
  • operator and operator-bundle images have the same git reference.

Currently we check only few basic labels, other will be decided later.

Other improvement is, that images are pulled only once for all the tests. This improves performance significantly.

Summary by Sourcery

Add utilities and tests for inspecting and validating Docker image labels, refactor existing image handling to reuse a shared pull function, and extend test support with generic map operations

New Features:

  • Provide PullImageIfNotPresentLocally to fetch Docker images only if missing
  • Add InspectImageForLabels and GetImageLabel to extract labels from Docker images
  • Introduce generic map utilities (GetMapKeysSorted, generic LogMap, LogMapByProvidedKeys) for test support

Enhancements:

  • Refactor RunImage and FileFromImage to reuse the new pull logic and remove duplicate code
  • Define ImageData struct to pair image names with their labels for easier test assertions

Tests:

  • Implement tests to confirm matching vcs-ref labels for operator and operator-bundle images
  • Implement tests that inspect and report label counts for all snapshot.json images

Summary by Sourcery

Add reusable utilities for pulling Docker images and inspecting their labels, refactor existing image handling to use the new pull logic, and extend acceptance tests to validate image labels using generic map helpers

New Features:

  • Add PullImageIfNotPresentLocally to fetch Docker images only when missing
  • Add InspectImageForLabels and GetImageLabel functions to extract labels from images
  • Introduce ImageData struct for pairing image definitions with their labels
  • Add RequiredImageLabels function to define expected image labels
  • Introduce generic map utilities (GetMapKeysSorted, LogMap, LogMapByProvidedKeys) for test support

Enhancements:

  • Refactor RunImage and FileFromImage to reuse shared pull logic and reduce duplicate code
  • Optimize tests to pull each image only once for improved performance

Tests:

  • Add test to verify operator and operator-bundle images share the same vcs-ref label
  • Add test to validate presence and correctness of required labels for all snapshot.json images

@sourcery-ai
Copy link

sourcery-ai bot commented Jul 30, 2025

Reviewer's Guide

This PR centralizes Docker image pulling logic, adds utilities for inspecting and retrieving image labels, introduces generic map helpers for tests, defines required image labels, and extends acceptance tests to validate image metadata.

File-Level Changes

Change Details Files
Abstract shared image pulling and integrate into existing image utilities
  • Added PullImageIfNotPresentLocally to centralize image pulls
  • Refactored RunImage to use shared pull logic and removed redundant pull code
  • Updated FileFromImage to invoke PullImageIfNotPresentLocally
test/support/image_utils.go
Introduce image label inspection and retrieval helpers
  • Defined InspectImageForLabels to extract all labels from an image
  • Added GetImageLabel to fetch a specific label value
  • Introduced ImageData struct for pairing image references with labels
test/support/image_utils.go
Extend generic map utilities for test support
  • Generalized GetMapKeys to support any value type
  • Added GetMapKeysSorted for deterministic key ordering
  • Introduced generic LogMap and LogMapByProvidedKeys for structured logging
test/support/common.go
Define and expose required image labels
  • Added RequiredImageLabels function enumerating mandatory labels and expected values
test/support/test_constants.go
Enhance acceptance tests to validate Docker image labels
  • Test that operator and operator-bundle share the same vcs-ref label
  • Validate all snapshot.json images contain required labels with correct values
test/acceptance/releases_images_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@petrpinkas petrpinkas marked this pull request as draft July 30, 2025 19:53
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @petrpinkas - I've reviewed your changes - here's some feedback:

  • You’re creating a new Docker client (and deferring Close) in almost every helper – consider centralizing client creation (and context passing) so you can reuse a single client and avoid repeated setup/teardown.
  • In FileFromImage you panic on client initialization failure – it would be better to return an error instead so the caller can handle failures gracefully rather than crashing the test binary.
  • Most functions call context.TODO(); accepting a context parameter from the caller would make it easier to manage timeouts and cancellations across these image operations.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- You’re creating a new Docker client (and deferring Close) in almost every helper – consider centralizing client creation (and context passing) so you can reuse a single client and avoid repeated setup/teardown.
- In FileFromImage you `panic` on client initialization failure – it would be better to return an error instead so the caller can handle failures gracefully rather than crashing the test binary.
- Most functions call context.TODO(); accepting a context parameter from the caller would make it easier to manage timeouts and cancellations across these image operations.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@petrpinkas
Copy link
Member Author

This is how labels report looks like:

[FAILED] Label validation errors found:
  quay.io/securesign/fbc-v4-16@sha256:40100b8e0042c1289963c7d930923f0127ea0cf876ff3e69231d2c2dc8756b26:
    short-commit: missing
    maintainer: Odin Team <aos-odin@redhat.com>, expected: Red Hat, Inc.
  quay.io/securesign/segment-backup-job@sha256:c22cdb9a17f85e13c00412cba83aa644e90a0faea0236029d0f1c53fe212e227:
    maintainer: SoftwareCollections.org <sclorg@redhat.com>, expected: Red Hat, Inc.
  quay.io/securesign/fbc-v4-15@sha256:be96e17bb6698e9d4ad0a5dc34a491f0f702b0aa86a969356d77c7abd7bc712b:
    short-commit: missing
    maintainer: Odin Team <aos-odin@redhat.com>, expected: Red Hat, Inc.
  quay.io/securesign/rekor-search-ui@sha256:fe31830df2d99359749cb86cd1ac2f32fcc3de07aae427d2f2cd3998d31d2833:
    maintainer: trusted-artifact-signer@redhat.com, expected: Red Hat, Inc.
  quay.io/securesign/rekor-backfill-redis@sha256:09b4aeeb607c88c72f69e6f87cb840c82ef5752c64a58fa13551db749fac2530:
    maintainer: SoftwareCollections.org <sclorg@redhat.com>, expected: Red Hat, Inc.
  quay.io/securesign/fbc-v4-17@sha256:3ddfa8d6b4171dfdd14e14d4f0b7c0829f5b6c3975be9c230df77f61c1ae8062:
    short-commit: missing
    maintainer: Odin Team <aos-odin@redhat.com>, expected: Red Hat, Inc.
  quay.io/securesign/trillian-database@sha256:640633823a54c11fe2a8b3d05e571399fda415b6f0b3adf1ba9806882a94bdd4:
    maintainer: SoftwareCollections.org <sclorg@redhat.com>, expected: Red Hat, Inc.
  quay.io/securesign/fbc-v4-14@sha256:ee381043e0b4ef4adc7d0f299b86844732eaed2332dd2d22939219da0a781d49:
    short-commit: missing
    maintainer: Odin Team <aos-odin@redhat.com>, expected: Red Hat, Inc.
  quay.io/securesign/rhtas-operator-bundle@sha256:1e17b082fbf3dbdabd00ee9fef5b7574caf87a32428a87fbe0921812066fbb13:
    maintainer: missing
  quay.io/securesign/fbc-v4-19@sha256:bd903f90cac2daf74634a42d9c3be441a053385a704e0dc9e24a1bdc62ff681a:
    short-commit: missing
    maintainer: Odin Team <aos-odin@redhat.com>, expected: Red Hat, Inc.
  quay.io/securesign/fbc-v4-18@sha256:3a1db66219674863524f4a753de1ddb5f4c78895e1455dede3f110cfddd67cb1:
    short-commit: missing
    maintainer: Odin Team <aos-odin@redhat.com>, expected: Red Hat, Inc.
  quay.io/securesign/trillian-redis@sha256:fc018a45b7eb48690c46c83f52cac55fa40089e6b02686bc21265dc7c2205b8f:
    maintainer: SoftwareCollections.org <sclorg@redhat.com>, expected: Red Hat, Inc.
  quay.io/securesign/client-server@sha256:1c2201d50469d70ec6e21546c7c74bd52251d420dc1dcfa5375c1cf61dd3a9fd:
    maintainer: trusted-artifact-signer@redhat.com, expected: Red Hat, Inc.

@petrpinkas petrpinkas marked this pull request as ready for review August 27, 2025 16:28
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Consider refactoring Docker client creation (and closing) into a shared helper so you don’t recreate a new client in every utility function.
  • In FileFromImage you’re panicking on client init error—switch that to returning an error to keep error handling consistent across your utilities.
  • Rather than using context.TODO inside InspectImageForLabels and PullImageIfNotPresentLocally, accept a context.Context parameter to enable cancellation and timeouts.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider refactoring Docker client creation (and closing) into a shared helper so you don’t recreate a new client in every utility function.
- In FileFromImage you’re panicking on client init error—switch that to returning an error to keep error handling consistent across your utilities.
- Rather than using context.TODO inside InspectImageForLabels and PullImageIfNotPresentLocally, accept a context.Context parameter to enable cancellation and timeouts.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@petrpinkas petrpinkas requested a review from kdacosta0 August 27, 2025 16:43
Copy link
Member

@kdacosta0 kdacosta0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR

I've left two minor comments in the code: one required typo fix and one non-blocking suggestion.

I tested this locally: the tests pass against the 1.3.0 snapshot and correctly fail when I introduce an invalid expectation - the logic works perfectly

LGTM, approved once the typo is addressed

@petrpinkas petrpinkas merged commit 08a7bb8 into main Aug 28, 2025
4 checks passed
@petrpinkas petrpinkas deleted the ppinkas/SECURESIGN-2606-images-lagels branch August 28, 2025 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants